<template>
  <div>
    <a-card class="card-header">
      <a-form-model :model="queryParam">
        <a-row :gutter="24">
          <a-col :span="5">
            <a-form-model-item
              label="订单号"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <a-input
                v-model.trim="queryParam.orderNumber"
                placeholder="请输入订单号"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="5" v-hasPromise="'ordermentDel'">
            <a-form-model-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="状态"
            >
              <a-select
                style="width: 100%"
                v-model.trim="queryParam.deleteFlag"
              >
                <a-select-option
                  v-for="item in deleteOption"
                  :key="item.value"
                  :value="item.value"
                >
                  {{ item.label }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="2">
            <a-button
              type="primary"
              style="margin-top:3px"
              @click="handleSearch"
              >查询</a-button
            >
          </a-col>
        </a-row>
      </a-form-model>
    </a-card>

    <a-card class="card-content">
      <a-row :gutter="24">
        <a-col :span="22">
          <a-button type="primary" @click="handleAdd">新建</a-button>
          <!-- <a-button
            type="primary"
            @click="handelExport('销售订单', 'orderPageList', columns)"
            >导出</a-button
          >
          <a-button type="primary">导入</a-button> -->
        </a-col>
        <a-col :span="2">
          <a-button type="primary" @click="handleAllList('orderPageList')"
            >全部销售订单</a-button
          >
        </a-col>
      </a-row>
      <br />
      <a-table
        :columns="columns"
        :scroll="{ x: 5000 }"
        :data-source="tableData"
        :loading="loading"
        :pagination="pagination"
        @change="handleTableChange"
        bordered
        :rowKey="(record, index) => record.id"
      >
        <template slot="action" slot-scope="text, record">
          <div v-if="record.deleteFlag === 'N'">
            <a @click="handleEdit(record)">编辑</a>
            <a-divider type="vertical" v-hasPromise="'ordermentDel'" />
            <a-popconfirm
              v-hasPromise="'ordermentDel'"
              okText="确定"
              cancelText="取消"
              title="确定删除吗?"
              @confirm="() => handleDelete(record)"
            >
              <a>删除</a>
            </a-popconfirm>
          </div>
          <a-popconfirm
            okText="确定"
            cancelText="取消"
            v-else
            title="确定恢复吗?"
            @confirm="() => handleRecovery(record)"
          >
            <a>恢复</a>
          </a-popconfirm>
        </template>
      </a-table>
    </a-card>

    <DemoModal
      ref="modalForm"
      :disabled="disabled"
      @ok="modalFormOk"
    ></DemoModal>
  </div>
</template>

<script>
import { columns } from "./components/tableConfig";
import { tableMinxins } from "@/unit/mixins/tableMinxins.js";
import DemoModal from "@/components/OrderMentModal.vue";
import api from "@/api/apiServer";
export default {
  components: { DemoModal },
  mixins: [tableMinxins],
  data() {
    return {
      columns,
      tableData: [],
      disabled: false,
    };
  },
  mounted() {
    this.getList();
    this.handleAllList("orderPageList");
  },
  methods: {
    // 获取列表数据
    async getList(arg) {
      this.loading = true;
      if (arg === 1) {
        this.pagination.current = 1;
      }
      var params = this.getQueryParams();
      const res = await api.orderPageList(params);
      this.tableData = res.data.data;
      this.pagination.total = res.data.total;
      this.loading = false;
    },
    // 删除
    async handleDelete(record) {
      const res = await api.orderDelete({
        id: record.id,
      });
      this.getList();
      this.$message.success(res.message);
    },
    // 恢复
    async handleRecovery(record) {
      let params = {
        id: record.id,
      };
      const res = await api.OrderRecovery(params);
      this.$message.success(res.message);
      this.getList();
    },
    // 新增
    handleAdd() {
      this.disabled = false;
      this.$refs.modalForm.title = "新增";
      this.$refs.modalForm.modalAdd();
    },
    //  编辑
    handleEdit(record) {
      this.disabled = true;
      this.$refs.modalForm.title = "编辑";
      this.$refs.modalForm.modalEdit(record);
    },
  },
};
</script>

<style lang="less" scoped>
.card-header {
  margin: 20px 0;
}
.card-content {
  button {
    margin-right: 20px;
  }
}
::v-deep .ant-form-item {
  margin-bottom: 0;
}
</style>
